package com.qfedu.mesadmin.md.type.controller;

import com.qfedu.mes.common.CommonResult;
import com.qfedu.mes.entity.md.MdItemType;
import com.qfedu.mesadmin.md.type.params.AddItemTypeParam;
import com.qfedu.mesadmin.md.type.service.MdItemTypeService;
import com.qfedu.mesadmin.md.type.vo.ItemTypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/md/type")
public class MdItemTypeController {

    @Resource
    private MdItemTypeService mdItemTypeService;

    @GetMapping("/list")
    public CommonResult listTypeTree() {
        List<ItemTypeVO> itemTypeVOS = mdItemTypeService.listTypeTree();
        return CommonResult.success(itemTypeVOS);
    }

    @GetMapping("/info")
    public CommonResult itemTypeInfo(Long id) {
        MdItemType mdItemType = mdItemTypeService.itemInfo(id);
        return CommonResult.success(mdItemType);
    }

    @PostMapping("/add")
    public CommonResult addItemType(@RequestBody AddItemTypeParam param) {
        mdItemTypeService.addItemType(param);
        return CommonResult.success();
    }

    @GetMapping("/delete")
    public CommonResult deleteType(Long id) {
        mdItemTypeService.deleteType(id);
        return CommonResult.success();
    }
}
